package com.tnl.app.dao;

import org.springframework.stereotype.Repository;

import com.tnl.app.entity.TbForm;
import com.tnl.base.BaseDAO;


@Repository
public class TbFormDAO {
	private static final String SQL_GET_ID = "select * from tb_formid where formid=";
	
	private static final String SQL_SAVE="insert into tb_formid(unionid,openid,formid,expire,wxapptype) VALUES(?,?,?,?,?)";
	
	private static final String SQL_DELETE="delete from tb_formid where formid=?";
	
	private static final String SQL_GET_BY_FORMID="select * from tb_formid where formid=? and wxapptype=?";
	public TbForm getFormid(String formid) {
		return  BaseDAO.queryForObject(TbForm.class, SQL_GET_ID);
	}
	
	public TbForm getFormidType(String formid,Integer type) {
		return  BaseDAO.queryForObject(TbForm.class, SQL_GET_BY_FORMID,formid,type);
	}
	
	public long save(TbForm form) {
		if (form == null) {
			return -1;
		}

		Long result = BaseDAO.save(SQL_SAVE, form.getUnionid(),form.getOpenid(),form.getFormid(),form.getExpire(),form.getWxapptype());
		if (result != null) {
			return result.longValue();
		}
		return -1;
	}
	
	public int delete(String formid) {
		if (formid!=null) {
			return -1;
		}
		return BaseDAO.execute(SQL_DELETE, formid);
	}
}
